<?php
/*
 * getting some data variables
 */
$username = Common::getLoginUsername();
$recentUsers = DataHelper::getRecentUserList(10);
$friends = DataHelper::getFriendList(10);
$friendCount = DataHelper::getFriendsCount();
$friendsAddedUser = DataHelper::getFriendsAddedUserList(5);
$friendAddedUserCount = DataHelper::getFriendAddedUserCount();

/*
 * generating some urls
 */
$profileURL = Common::getBaseUrl().'user/profile/';
$loginURL = Common::getBaseUrl().'user/login';
$updateURL = Common::getBaseUrl().'user/update';
$changePassURL = Common::getBaseUrl().'user/changepassword';
$logoutURL = Common::getBaseUrl().'user/logout';
$registerURL = Common::getBaseUrl().'user/register';
$shareURL = Common::getBaseUrl().'user/profile';
$friendURL = Common::getBaseUrl().'user/friends';
$friendAddedUserURL = Common::getBaseUrl().'user/friendsadded';
$listUsersURL = Common::getBaseUrl().'user/list';
$requestsURL = Common::getBaseUrl().'user/requests';
?>
<!DOCTYPE html>
<html>
<head>
	<title></title>
   <!--[if lt IE 9]>;
   <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>;
	<![endif]-->
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<link type="text/css" href="/template/css/global.css" rel="stylesheet">
	<link type="text/css" rel="stylesheet" href="/template/css/style.css" />
   <link type="text/css" href="/template/css/share.css" rel="stylesheet">
   <link type="text/css" href="/template/css/user.css" rel="stylesheet">

</head>
<body>
<div id="container">
		
	<!-- Header -->
	<header>
		<h1><a href="/">YASNS: <span>Yet another social networking site…</span></a> <sup>beta!</sup></h1>
	</header>

   <!-- left side -->
   <aside id="leftside">
      <!-- Info Section -->
      <section class="info">
      	<h4>About</h4>
         <p>What is "Yet another social networking site?" It is yet another social networking site. Okay?</p>
      </section>

      <!-- Check if user is logged in -->
      <?php if (!$username): ?>
      <!-- User Not logged in, Guest Welcome Section -->
      <section>
         <h4>Welcome, guest!</h4>
         <p><a href="<?php echo $loginURL; ?>">Login</a> | <a href="<?php echo $registerURL; ?>">Register</a></p>
         <br />

         <?php if ($_SERVER['PHP_SELF'] != '/index.php/user/login') :?>
         <form method="post" action="/user/login">
			<p>
				<label for="user"><small>Username:</small></label><br/><input type="text" id="user" name="user" value="<?php echo @$_POST['user'] ?>">
			</p>
			<p>
				<label for="pass"><small>Password:</small></label><br/><input type="password" id="pass" name="pass">
			</p>
			<p>
				<input type="submit" value="Login" id="submit" name="submitLogin">
			</p>
		</form>
         <p><em>Haven't registered yet? Registering is easy as 1, 2… <a href="/user/register">Register</a></em></p>
         <?php endif ?>
      </section>
      
      

      <!-- User logged in, User Menu -->
      <?php else: ?>

      <!-- User Welcome Section -->
      <section>
         <h4>Welcome, <?php echo $username; ?>!</h4>
         <ul>
            <li><a href="<?php echo $profileURL; ?>">My Profile</a></li>
            <li><a href="<?php echo $updateURL; ?>">Update Info</a></li>
            <li><a href="<?php echo $changePassURL; ?>">Change Password</a></li>
            <li><a href="<?php echo $logoutURL; ?>">Logout</a></li>
         </ul>
      </section>
      <!-- User Stuff Section -->
      <section>
         <h4>My Stuffs</h4>
         <ul>
            <li><a href="<?php echo $shareURL; ?>?t=Status">Status</a></li>
            <li><a href="<?php echo $shareURL; ?>?t=Shoutout">Shouts</a></li>
            <li><a href="<?php echo $shareURL; ?>?t=Link">Links</a></li>
            <li><a href="<?php echo $shareURL; ?>">All</a></li>
         </ul>
      </section>
      <?php endif; ?>
      <?php if ($username): ?>
      <!-- My Friend List -->
      <section>
         <h4>My Friends (<?php echo $friendCount; ?>)</h4>
         <?php if ($username): ?>
         <ul>
         	<?php
            if ($friends) :
            foreach($friends as $friend): ?>
            <li><a href="/user/profile/<?php echo $friend['username'] ?>"><?php echo $friend['username']; ?></a></li>
         	<?php endforeach; ?>
            <?php endif; ?>
         	<li><strong><a href="/user/list">Add friends</a></strong></li>
         </ul>
         <?php endif; ?>
      </section>

      <!-- Users added Me List -->
      <section>
         <h4>Users who added me (<?php echo $friendAddedUserCount; ?>)</h4>
         <?php if ($username): ?>
         <ul>
         	<?php
            if ($friendsAddedUser) :
            foreach($friendsAddedUser as $friend): ?>
            <li><?php echo substr($friend['username'],0,16); ?></li>
         	<?php endforeach; ?>
            <li><a href="<?php echo $friendAddedUserURL; ?>">View all…</a></li>
            <?php else: ?>
            <li><small><em>No one added you as friend yet :(</em></small></li>
            <?php endif; ?>         	
         </ul>
         
         <?php endif; ?>
      </section>
      <?php endif; ?>
      
      <br />
      <section class="info">
         <h4>Concern about privacy?</h4>
         <p>You should be. There is no privacy online. Everything you post will be publicly visible.</p>
      </section>

   </aside>
   
	<!-- Main Section -->
		<!-- Content, viewscript -->
	<section id="content"><?php echo $this->VIEW_CONTENT ?></section>
   
   <!-- Right Sidebar -->
   <aside id="rightside">
   	  <section>
   	  <h4>Recent Users</h4>
      <?php if ($recentUsers): ?>
      <ul>
         <?php
            foreach($recentUsers as $recentUser): 
         ?>
         <li><a href="<?php echo $profileURL.$recentUser['username']; ?>"><?php echo substr($recentUser['username'],0,16) ?></a></li>
         <?php	
            endforeach;
         ?>
      </ul>
      <a href="<?php echo $listUsersURL; ?>">All Users</a>
      <?php endif; ?>
   	  </section>
      
      
      <br />
      <br />
      <section>
      <h4>Upcoming features</h4>
      <ul>
      	<li>Like/dislike posts</li>
      	<li>Group friends</li>
      	<li>add images</li>
      </ul>
      </section>
   </aside>
   
   <footer>
   		<p>A CSC478 Project @ University of Illinois at Springfield | Spring 2012 | By Alamin, David and John</p>
		<p>Open source, hosted at <a href="http://yasns.googlecode.com">http://yasns.googlecode.com</a> | best when viewed IE 9+, Safari 3+, Firefox 5+</p>
   </footer>
</div>
</body>
</html>